<template>
  <el-dialog :visible="showRole" title="分配角色" @close="cancelDialog">
    <el-checkbox-group v-model="ids">
      <el-checkbox v-for="item in roleList" :key="item.id" :label="item.id">{{item.name}}</el-checkbox>
    </el-checkbox-group>
    <el-row type="flex" justify="center" style="margin-top:30px">
      <el-button size="small" type="success" @click="doRole">确定</el-button>
      <el-button size="small" @click="cancelDialog">取消</el-button>
    </el-row>
  </el-dialog>
</template>

<script>
import { getRoleList } from '@/api/setting'
import {userProfile} from '@/api/user'
import {setRole} from '@/api/employees'
export default {
  props: {
    showRole: {
      type: Boolean,
      default: false
    },
    userId: {
      type: String,
      default: '',
      required: true
    }
  },
  data () {
    return {
      roleList: [],
      ids:[]
    }
  },
  created () {
    this.getRoleList()
  },
  methods: {
    async getRoleList () {
      let res = await getRoleList({ page: 1, pagesize: 999999 })
      // console.log(res)
      this.roleList=res.data.rows
    },
    async getUserProfile(id){
     let res= await userProfile(id)
    //  console.log(res);
    this.ids=res.data.roleIds
    },
    cancelDialog(){
      this.$emit('update:showRole',false)
      this.ids=[]
    },
   async doRole(){
      await setRole({
        id:this.userId,roleIds:this.ids
      })
        this.$message.success('分配角色修改成功!')
        this.cancelDialog()
    }
  }
}
</script>

<style></style>
